﻿
CKEDITOR.plugins.add('OfficeIframe', {
    requires: "dialog,fakeobjects",
    onLoad: function () {
        CKEDITOR.addCss("img.cke_iframe{background-image: url(" + CKEDITOR.getUrl(this.path + "images/placeholder.png") + ");background-position: center center;background-repeat: no-repeat;border: 1px solid #a9a9a9;width: 80px;height: 80px;}")
    },
    afterInit: function (a) {
        var b = a.dataProcessor;
        (b = b && b.dataFilter) && b.addRules({
            elements: {
                iframe: function (b) {
                    return a.createFakeParserElement(b, "cke_iframe", "iframe", !0)
                }
            }
        })
    },
    init: function (a) {
        var pluginName = 'OfficeIframe';

        var b = c = "iframe[align,longdesc,frameborder,height,name,scrolling,src,title,width,data-pdf]";
        a.plugins.dialogadvtab && (c += ";iframe" + a.plugins.dialogadvtab.allowedContent({
            id: 1,
            classes: 1,
            styles: 1
        }));

        CKEDITOR.dialog.add(pluginName, this.path + "dialogs/officeiframe.js");
        a.addCommand(pluginName, new CKEDITOR.dialogCommand(pluginName));
        a.ui.addButton && a.ui.addButton(pluginName, {
            label: "文档上传",
            icon: this.path + 'images/icon.png',
            command: pluginName,
            toolbar: "insert,80"
        });
        a.on("doubleclick", function (a) {
            var b = a.data.element;
            b.is("img") && "iframe" == b.data("cke-real-element-type") && (a.data.dialog = pluginName)
        });

        a.removeMenuItem("iframe");//去除默认的iframe
        a.addMenuGroup('docsGroup');
        a.addMenuItems && a.addMenuItems({
            docItem: {
                label: "编辑文档",
                command: pluginName,
                group: "docsGroup"
            }
        });
        a.contextMenu && a.contextMenu.addListener(function (a) {
            if (a && a.is("img") && "iframe" == a.data("cke-real-element-type")) return {
                docItem: CKEDITOR.TRISTATE_OFF
            }
        });
    }
});